import { createStore } from "vuex";
import app from './modules/app'

type UserInfo = {
  name: string;
  avatar: string;
  id: string;
  phone: string;
};
type LoginState = {
  count: number;
  isLogin?: boolean;
  userInfo?: UserInfo;
};
// 创建一个新的 store 实例
const store = createStore({
  state() {
    return {
      isLogin: false,
      count: 0,
    };
  },
  mutations: {
    increment(state: LoginState) {
      state.count++;
    },
    login(state: LoginState,username:string){
      state.isLogin=true
      sessionStorage.setItem('isLogin',username)
    },
    logout(state: LoginState){
      state.isLogin=false
      sessionStorage.removeItem('isLogin')
    },
  },
  modules:{
    app
  }
});
export default store
